<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>公司信息</title>
    <link rel="icon" href="/image/favicon.ico" type="image/x-icon"/>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            display: flex;
            flex-direction: column;
            height: 100vh;
            background-color: #f4f4f9;
        }
        .top-nav {
            width: 100%;
            height: 50px;
            background-color: black;
            color: white;
            text-align: left;
            padding: 0;
        }
        .top-nav h1 {
            margin: 8px;
            font-size: 24px;
        }
        .top-nav .close{
            float:right;
            display: block;
            color: white;
        }
        .main-content {
            display: flex;
            flex-grow: 1;
        }
        .sidebar {
            width: 200px;
            background-color: #444;
            display: flex;
            flex-direction: column;
            padding-top: 20px;
        }
        .sidebar button {
            padding: 15px;
            margin: 10px;
            background-color: #555;
            border: none;
            color: white;
            text-align: center;
            font-size: 16px;
            cursor: pointer;
            border-radius: 4px;
        }
        .sidebar button:hover {
            background-color: #666;
        }
        .content {
            flex-grow: 1;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            margin: 20px;
            border-radius: 8px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
        }
        .form-group input {
            padding: 10px;
            box-sizing: border-box;
            font-size: 14px;
            width: 250px; /* 缩小文本框的宽度 */
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .buttons {
            display: flex;
            justify-content: flex-start;
            margin-top: 20px;
        }
        .button {
            padding: 15px 30px; /* 增加按钮的内边距 */
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
            font-size: 18px; /* 增大按钮的字体大小 */
            border-radius: 4px;
        }
        .button:hover {
            background-color: #45a049;
        }
        .text{
            width: 50%;
            height: 200px; /* 或其他所需高度 */
            resize: both; /* 允许用户调整大小 */
        }
        #pingtu1{
            display: block;
            float: left;
        }
        
    </style>
</head>
<body>
<div class="top-nav">
    <h1 id="pingtu1">聘途</h1>
    <a class="close" href="/登录注册/用户登录.html"><h1>退出登录</h1></a>
</div>
<div id="app" class="main-content">
    <div class="sidebar">
        <button @click="navigateTo('公司端-首页.html')">岗位招聘</button>
        <button @click="navigateTo('公司端-公司信息.html')">公司信息</button>
    </div>
    <div class="content">
        <h2>公司信息</h2>
        <div class="form-group">
            <label for="cname">公司名</label>
            <input type="text" id="cname" v-model="cname">
        </div>
        <div class="form-group">
            <label for="cyear">成立年份</label>
            <input type="text" id="cyear" v-model="cyear">
        </div>
        <div class="form-group">
            <label for="caddress">公司地址</label>
            <input type="text" id="caddress" v-model="caddress">
        </div>
        <div class="form-group">
            <label for="cemail">公司邮箱</label>
            <input type="text" id="cemail" v-model="cemail">
        </div>
        <div class="form-group">
            <label for="cphone">公司电话</label>
            <input type="text" id="cphone" v-model="cphone">
        </div>
        <div>
            <textarea class="text" v-model="fileContent"></textarea>
        </div>
        <div class="buttons">
            <button class="button" @click="update">修改信息</button>
        </div>

    </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
    var CompanyInfo = JSON.parse(sessionStorage.getItem('userData'));
    new Vue({
        el: '#app',
        data: {
            cusername:'',
            cname: '',
            cyear: '',
            caddress: '',
            cemail: '',
            cphone: '',
            cinfo: '',
            fileContent: ''
        },
        created() {
            this.fetchData();
        },
        methods: {
            fetchFileContent() {
                // 使用 Axios 从后端获取文件内容
                let data = new FormData();
                //改动2
                data.append("cinfo", this.cinfo);
                //改动3
                axios.post("http://localhost:8080/hqdx/company/showCompanyProfile",data)
                    .then(response => {
                        this.fileContent = response.data.data.items; // 更新Vue实例的数据
                    })
                    .catch(error => {
                        console.error('Error fetching file content:', error);
                    });
            },
            fetchData() {
                        this.cname = CompanyInfo.cname;
                        this.cyear = CompanyInfo.cyear;
                        this.caddress = CompanyInfo.caddress;
                        this.cemail = CompanyInfo.cemail;
                        this.cphone = CompanyInfo.cphone;
                        this.cinfo = CompanyInfo.cinfo;
                        this.fetchFileContent();
                    
            },
            navigateTo(page) {
                window.location.href = page;
            },
            update() {
                let data3 = new FormData();
                this.cusername=CompanyInfo.cusername;
                data3.append("cusername",this.cusername);
                data3.append("cname", this.cname);
                data3.append("caddress", this.caddress);
                data3.append("cemail", this.cemail);
                data3.append("cphone", this.cphone);
                data3.append("cyear", this.cyear);
                console.log(this.cyear);
                data3.append("cv", this.fileContent);
                axios.post('http://localhost:8080/hqdx/company/updateComMessage', data3)
                    .then(response => {
                        sessionStorage.getItem('userData').cname=this.cname;
                        CompanyInfo.cyear=this.cyear;
                        CompanyInfo.caddress=this.caddress;
                        CompanyInfo.cemail=this.cemail;
                        CompanyInfo.cphone=this.cphone;
                        sessionStorage.setItem('userData', JSON.stringify(CompanyInfo));
                        alert('信息更新成功！');
                        this.fetchData();
                    })
                    .catch(error => {
                        console.log(error);
                    });
            }
        }
    });
</script>
</body>
</html>
